﻿using DFGJ.WMS_PDA.WebAPI.Utility.Attributes;
using DFGK_WMS.Context;
using DFGK_WMS.IRepository;
using DFGK_WMS.WebAPI.Controllers.Result;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DFGJ.WMS_PDA.WebAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Head("移库PDA指令")]
    //[Authorize()]
    public class RemoveInventoryController : ApiBaseController
    {
        private readonly ITransferBinOrderRepository _transferRespository;

        public RemoveInventoryController(DFGK_DB context, ITransferBinOrderRepository transferRespository) : base(context)
        {
            _transferRespository = transferRespository;
        }



        [HttpGet]
        [Route("GetLog")]
        public void GetLog()
        {
            var result = base.Log("测试Log");
        }


        [Function("仓位移库分配")]
        [HttpGet]
        [Route("SubmitTransferCell/{id}")]
        public IActionResult SubmitTransferCell(int id)
        {
            try
            {
                base.Log("开始生成移位指令，移库指令ID:" + id);

                string errMsg;
                bool boolResult = _transferRespository.SubmitTransferCell(id, out errMsg);

                base.Log("移库指令生成结束,移库指令ID:" + id + $",执行结果：{(boolResult ? "成功 " : "【" + errMsg + "】")}");

                if (boolResult)
                {
                    return new JsonResult(BaseResult.Result("移库指令生成完成", code: "200"));
                }
                else
                {
                    return new JsonResult(BaseResult.Result("创建移库单任务出错：" + errMsg, code: "500"));
                }


            }
            catch (Exception ex)
            {
                return new JsonResult(BaseResult.Result(message: ex.Message, code: "500"));

            }


        }


    }
}
